package nutrients.p3_fitnessapp;

import java.text.DecimalFormat;

import android.util.Log;

public class Nutrientscalc {


	// Format fuer die Ausgabe
	DecimalFormat format = new DecimalFormat("#0.00");


	/*
	 * ====================================================================
	 * Globale Variablen
	 */



	private int _smrLight;
	private double _smrFull;

	private int _bmi;

	private double _protein = 4.1;
	private double _carbo = 4.1;
	private double _fat = 9.1;


	private double _proteinResult;
	private double _carboResult;
	private double _fatResult;

	/*
	 * Aufbauphase
	 */

	private double _prot_ekto_build = 10;
	private double _prot_meso_build = 25;
	private double _prot_endo_build = 30;

	private double _carbo_ekto_build = 65;
	private double _carbo_meso_build = 65;
	private double _carbo_endo_build = 50;

	private double _fat_ekto_build = 25;
	private double _fat_meso_build = 10;
	private double _fat_endo_build = 10;

	/*
	 * Definitionsphase
	 */

	private double _prot_ekto_def = 25;
	private double _prot_meso_def = 50;
	private double _prot_endo_def = 60;

	private double _carbo_ekto_def = 55;
	private double _carbo_meso_def = 45;
	private double _carbo_endo_def = 35;

	private double _fat_ekto_def = 20;
	private double _fat_meso_def = 5;
	private double _fat_endo_def = 5;
	/*
	 * Aufbauphase
	 */

	private double _prot_ekto_comp = 25;
	private double _prot_meso_comp = 50;
	private double _prot_endo_comp = 60;

	private double _carbo_ekto_comp = 55;
	private double _carbo_meso_comp = 45;
	private double _carbo_endo_comp = 35;

	private double _fat_ekto_comp = 20;
	private double _fat_meso_comp = 5;
	private double _fat_endo_comp = 5;

	/*
	 * ====================================================================
	 * Konstruktor
	 */

	/*
	 * ====================================================================
	 * Methoden Eingabe
	 */

	/*
	 * ====================================================================
	 * Methoden Berechnung
	 */

	public int calculateSMRLight(int weight) {

		_smrLight = weight * 24;

		return _smrLight;

	}

	public double calculateSMRFull(int weight, int work, int sport) {
		_smrFull = calculateSMRLight(weight) + (work + sport);
		return _smrFull;

	}

	public ResultNutrients calculateDetailed(String phase, String bodytype) {

		Log.e(null, "");

		ResultNutrients result = new ResultNutrients();

		Log.d(null, "calc Phase " + phase);
		Log.d(null, "calc type " + bodytype);

		String aufbau = "Aufbau";
		String definition = "Definition";
		String wettkampf = "Wettkampf";

		String endo = "Endomorph";
		String ekto = "Ektomorph";
		String meso = "Mesomorph";

		Log.d(null, "BEVOR if");

		if (phase.equals(aufbau)) {

			Log.d(null, "if aufbau");

			if (bodytype.equals(endo)) {

				Log.d(null, "smr : " + _smrFull);
				Log.d(null, "smr : " + _smrLight);

				_proteinResult = _smrFull * (_prot_endo_build / 100) / _protein;
				_carboResult = _smrFull * (_carbo_endo_build / 100) / _carbo;
				_fatResult = _smrFull * (_fat_endo_build / 100) / _fat;

			} else if (bodytype.equals(ekto)) {

				_proteinResult = _smrFull * (_prot_ekto_build / 100) / _protein;
				_carboResult = _smrFull * (_carbo_ekto_build / 100) / _carbo;
				_fatResult = _smrFull * (_fat_ekto_build / 100) / _fat;

			} else if (bodytype.equals(meso)) {

				_proteinResult = _smrFull * (_prot_meso_build / 100) / _protein;
				_carboResult = _smrFull * (_carbo_meso_build / 100) / _carbo;
				_fatResult = _smrFull * (_fat_meso_build / 100) / _fat;

			} else {

				Log.e(null, "Fehler beim Typ " + bodytype);

			}

		} else if (phase.equals(definition)) {

			if (bodytype.equals(endo)) {

				Log.d(null, "smr : " + _smrFull);
				Log.d(null, "smr : " + _smrLight);

				_proteinResult = _smrFull * (_prot_endo_def / 100) / _protein;
				_carboResult = _smrFull * (_carbo_endo_def / 100) / _carbo;
				_fatResult = _smrFull * (_fat_endo_def / 100) / _fat;

			} else if (bodytype.equals(ekto)) {

				_proteinResult = _smrFull * (_prot_ekto_def / 100) / _protein;
				_carboResult = _smrFull * (_carbo_ekto_def / 100) / _carbo;
				_fatResult = _smrFull * (_fat_ekto_def / 100) / _fat;

			} else if (bodytype.equals(meso)) {

				_proteinResult = _smrFull * (_prot_meso_def / 100) / _protein;
				_carboResult = _smrFull * (_carbo_meso_def / 100) / _carbo;
				_fatResult = _smrFull * (_fat_meso_def / 100) / _fat;

			} else {

				Log.e(null, "Fehler beim Typ " + bodytype);

			}



		} else if (phase.equals(wettkampf)) {
			if (bodytype.equals(endo)) {

				Log.d(null, "smr : " + _smrFull);
				Log.d(null, "smr : " + _smrLight);

				_proteinResult = _smrFull * (_prot_endo_comp / 100) / _protein;
				_carboResult = _smrFull * (_carbo_endo_comp / 100) / _carbo;
				_fatResult = _smrFull * (_fat_endo_comp / 100) / _fat;

			} else if (bodytype.equals(ekto)) {

				_proteinResult = _smrFull * (_prot_ekto_comp / 100) / _protein;
				_carboResult = _smrFull * (_carbo_ekto_comp / 100) / _carbo;
				_fatResult = _smrFull * (_fat_ekto_comp / 100) / _fat;

			} else if (bodytype.equals(meso)) {

				_proteinResult = _smrFull * (_prot_meso_comp / 100) / _protein;
				_carboResult = _smrFull * (_carbo_meso_comp / 100) / _carbo;
				_fatResult = _smrFull * (_fat_meso_comp / 100) / _fat;

			} else {

				Log.e(null, "Fehler beim Typ " + bodytype);

			}

		} else {
			Log.e(null, "Fehler bei der Phase " + phase);

		}

		Log.d(null, "Bodytype : " + bodytype);
		Log.d(null, "Phase : " + phase);
		Log.d(null, "Werte in g . Protein : " + format.format(_proteinResult)
				+ " Kohlenhydrate : " + format.format(_carboResult)
				+ " Fette : " + format.format(_fatResult));

		result.setCarbon(_carboResult);
		result.setFat(_fatResult);
		result.setProtein(_proteinResult);

		return result;

	}

	public int calculateBMI(double bodySize, int weight) {

		bodySize = bodySize / 100;
		Log.d(null, "bodysize : " + bodySize);

		_bmi = (int) (weight / (bodySize * bodySize));
		// _bmi = _weight / _bodySize;

		Log.d(null, "BMI : " + _bmi);

		return _bmi;

	}

	/*
	 * ====================================================================
	 * Ausgabe
	 */

	/*
	 * ====================================================================
	 * Getter und Setter
	 */

	public double get_smrLight() {
		return _smrLight;
	}

	public void set_smrLight(int _smrLight) {
		this._smrLight = _smrLight;
	}

	public double get_smrFull() {
		return _smrFull;
	}

	public void set_smrFull(double _smrFull) {
		this._smrFull = _smrFull;
	}

}
